package com.test.personalblogproject.utils;

import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class MailUtil {

        //注意这里一定要和Mail配置中的邮箱对应，不然无法成功发送
        public static final String FROM_EMAIL="2145507446@qq.com";

        /**
         * 发送邮件的方法,传入的参数 邮件发送器，目标邮箱，关键验证码信息
         * @param mailSender
         * @param toEmail
         * @param token
         */
        public static void sendResetMail(MailSender mailSender, String toEmail, String token){

            String url = "http://localhost:8080/reset-password?token=" + token; // 前端路由
            //String url = "http://localhost:8080/reset-password?token=" + URLEncoder.encode(token);
            SimpleMailMessage msg = new SimpleMailMessage();
            msg.setFrom("2145507446@qq.com");
            msg.setTo(toEmail);
            msg.setSubject("个人博客-重置密码");
            msg.setText("点击以下链接重置密码（30 min 内有效）：\n" + url);
            mailSender.send(msg);
        }



}
